<?php
include_once 'resource/output_functions.inc.php';
include_once 'models/transact/transact_user.inc.php';

include "resource/layout/header.php";
?>

<body>
    <div class="container">

        <form id="login" action="?action=login" class="form-login" method="post">
            <h2 class="form-login-heading">Identificaci&oacute;n</h2>
            <div id="error">            
                <?php
                if (!empty($errores)) {
                    mostrarErrores($errores);
                }
                ?>
            </div>
            <input name="usuario" type="text" class="form-control" placeholder="12345678X" required>
            <input name="password" type="password" class="form-control" placeholder="********" required>
            <label class="checkbox">
                <input type="checkbox" value="remember-me"> Recuerdame
            </label>
            <button name="enviar"  type="submit" class="btn btn-lg btn-primary btn-block">Entrar</button>
            <input name="redirect" type="hidden" value="<?php echo $redirect; ?>">
        </form>

    </div>
    <script>
        $("#login").submit(function() {
            $("#error").empty();
            var dni = $("input[name='usuario']").val();
            var pass = $("input[name='password']").val().length;
            if (!(res1 = checkDNI(dni)))
                $("#error").append($("<div>").addClass("alert alert-danger").append("No ha introducido un DNI valido"));
            if (!(res2 = (pass > 0)))
                $("#error").append($("<div>").addClass("alert alert-danger").append("No ha indicado correctamente la contrase&ntilde;a"));
            return res1 && res2;
        });
    </script>
</body>

<?php include "resource/layout/footer.php" ?>
